package com.itbaima.mapper;

import com.itbaima.pojo.entity.Department;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface DepartmentMapper {

    /**
     * 查询所有三级部门
     * @return
     */
    @Select("select * from departments where level = 3 ")
    List<Department> selectLevel3dp();

    @Select("select * from departments where department_id = #{dpParentId} and level = #{level} ")
    List<Department> selectLevelUpDp(Integer level, Integer dpParentId);

    @Select("select * from departments where department_id = #{dpParentId} and level = #{level} ")
    Department selectLevel2Dp(Integer level, Integer dpParentId);

    /**
     * 获取当前部门的信息
     * @param department_id
     * @return
     */
    @Select("select * from departments where department_id = #{department_id} ")
    Department getRecentDepartment(Integer department_id);

    /**
     * 获取当前部门的父类id
     * @param parent_id
     * @return
     */
    @Select("select * from departments where department_id = #{parent_id}  ")
    Department getparentId(Integer parent_id);


    /**
     * 获取当前部门的子类id
     * @param department_id
     * @return
     */
    @Select("select * from departments where parent_id = #{department_id}  ")
    Department getSonId(Integer department_id);

    @Delete("delete  from departments where id = #{id}")
    void deleteDP(Integer id);


    // 根据部门名称查询部门信息
    @Select("SELECT * FROM departments WHERE department_name = #{departmentName}")
    Department selectByDepartmentName(String departmentName);

}
